<template>
	<view class="erweima">
		<view class="uni-padding-wrap uni-common-mt">
			<uni-segmented-control :current="current" :values="items" :style-type="styleType" :active-color="activeColor" @clickItem="onClickItem" />
		</view>
		<view class="con" v-show="current === 0" style="padding-top: 30rpx;">
				<view class="item" v-for="(item,index) in ploatformlist" :key="index">
				<view class="title">
					<view class="left">{{item['ploat_name']}}二维码</view>
					<view class="right" @click="addewm(item)"><image mode="widthFix" src="../../../static/images/icon/add.png"></image></view>
				</view>
				<view class="con" v-for="(item1,index) in qrcodelist.qrcode_list" :key="index" v-if=" parseInt(item.id)  == item1.ploatform_id">
					<view class="contop">
						<view class="left">
							<image mode="widthFix" v-if="item1.status==1" src="../../../static/images/icon/blue.png"></image>
							<image mode="widthFix" v-else src="../../../static/images/icon/greyewm.png"></image>
						</view>
						<view class="middle">
							<view>账户：{{item1.account}}</view>
							<view>姓名：{{item1.nickname}}</view>
						</view>
						<view class="right">
							<switch :checked="item1.status==1?true:false" @change="switch1Change($event,item1)" />
						</view>
					</view>
					<view class="bottom">
						
						<text @tap="update(item,item1)">修改</text>
						<text class="red" @tap="remove(item1)">移除</text>
					</view>	
					
				</view>
				<view class="wu" v-if="datalength(item) == 0">
					暂无二维码
				</view>
				
			</view>
		</view>
		<view class="con" v-show="current === 1" style="padding-top: 30rpx;">
				<view class="item">
				<view class="title">
					<view class="left">银行卡</view>
					<view class="right"  @click="addewm1()"><image mode="widthFix" src="../../../static/images/icon/add.png"></image></view>
				</view>
				<view class="con"   v-for="(item,index) in qrcodelist.bank_list" :key="index">
					<view class="contop">
						<view class="left">
							<image mode="widthFix" :src="item.bank_logo"></image>
						</view>
						<view class="middle">
							<view>账户：{{item.account}}</view>
							<view>昵称：{{item.nickname}}</view>
						</view>
						<view class="right">
							<switch checked @change="switch1Change($event,item)" />
						</view>
					</view>
					<view class="bottom">
						<text @tap="undatebank(item)">修改</text>
						<text class="red" @tap="remove(item)">移除</text>
					</view>	
				</view>
				<!-- {{qrcodelist.bank_list.length}} -->
				<view class="wu" v-if="datalength1(qrcodelist.bank_list) == 0"  >
					暂无银行卡
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import uniSegmentedControl from '@/components/uni-segmented-control/uni-segmented-control.vue'
	import { mapState } from 'vuex';
	var _this;
	export default {
		components: {
			uniSegmentedControl
		},
		data() {
			return {
			items: ['二维码', '银行卡'],
			styles: [{
					value: 'button',
					text: '按钮',
					checked: true
				},
				{
					value: 'text',
					text: '文字'
				}
			],
			colors: ['#007aff', '#4cd964', '#dd524d'],
			current: 0,
			colorIndex: 0,
			activeColor: '#007aff',
			styleType: 'button'
				}
			},
		methods: {
			onClickItem(index) {
				if (this.current !== index) {
					this.current = index
				}
			},
			switch1Change: function (e,item1) {
				var  status;
				if(e.target.value==true){
					status = 1;
				}
				else{
					status = 2;
				}
				var data={
					token: uni.getStorageSync('token'),
					qrcode_id:item1.qrcode_id,
					status:status
				}
				_this.$store.dispatch("editqrcodestatus",data)
				.then(res => {
					uni.showToast({
						title: res.data.msg,
						icon: 'none'
					});
					if(res.data.code==1){
						var data = {
							token: uni.getStorageSync('token')
						};
						_this.$store.dispatch('qrcodelist', data);
					}
				})
        },
		update(item,item1){
			var pingtai;
			for(let i =0; i<this.ploatformlist.length; i ++){
				if(item1.ploatform_id == this.ploatformlist[i]['id'] *1){
					pingtai = this.ploatformlist[i];
				}
			}
			if(item1.ploatform_id == 2){
				uni.navigateTo({
					url:'../updaterweima/index?id=' + item1.ploatform_id + "&single_min="+ item1.single_min+ "&single_max="+ item1.single_max+ "&total_max="+ item1.total_max+ "&userId="+ item1.userId+ "&name="+ pingtai.ploat_name + "&explain=" + pingtai.explain +"&img_url="+item1.img_url + "&nickname="+item1.nickname + "&account=" +item1.account +"&qrcode_id=" + item1.qrcode_id
					
				})
			}
			else{
				uni.navigateTo({
					url:'../updaterweima/index?id=' + item1.ploatform_id + "&single_min="+ item1.single_min+ "&single_max="+ item1.single_max+ "&total_max="+ item1.total_max+ "&name="+ pingtai.ploat_name + "&explain=" + pingtai.explain +"&img_url="+item1.img_url + "&nickname="+item1.nickname + "&account=" +item1.account +"&qrcode_id=" + item1.qrcode_id
					
				})
			}
			
		},
		undatebank(item){
			uni.navigateTo({
				url:'../updatebank/index?nickname='+item.nickname + "&single_min="+ item.single_min+ "&single_max="+ item.single_max+ "&total_max="+ item.total_max+ "&account=" +item.account +"&qrcode_id=" + + item.qrcode_id+"&bankid=" + item.bank_id+"&bank_khh=" + item.bank_khh
			})
			
		},
		addewm(item){
			uni.navigateTo({
			  url:'../adderweima/index?id=' + item.id + "&name="+ item.ploat_name + "&explain=" + item.explain
			})	
			
		},
		addewm1(item){
			uni.navigateTo({
				url:'../addbank/index'
			})
			// uni.navigateTo({
			//   url:'../adderweima/index?id=' + item.id + "&name="+ item.ploat_name + "&explain=" + item.explain
			// })	
			
		},
		remove(item1){
				uni.showModal({
				content: `确定移除二维码？`,
				success: function(res) {
					if (res.confirm) {
						var data={
							token: uni.getStorageSync('token'),
							qrcode_id:item1.qrcode_id,
							status:3
						}
						_this.$store.dispatch("editqrcodestatus",data)
						.then(res => {
							uni.showToast({
								title: res.data.msg,
								icon: 'none'
							});
							if(res.data.code==1){
								var data = {
									token: uni.getStorageSync('token')
								};
								_this.$store.dispatch('qrcodelist', data);
							}
						})
						
					} else if (res.cancel) {
						console.log('用户点击取消');
					}
				}
			});
		}
		},
		
		onLoad() {
			_this = this;
		var data = {
			token: uni.getStorageSync('token')
		};
		this.$store.dispatch('ploatformlist', data);	
		this.$store.dispatch('qrcodelist', data);
		console.log()
		},
			computed: {
			...mapState([
				"ploatformlist",
				"qrcodelist",
		
			]),
			datalength() {
				return function(item) {
					var flag = 0;
					if(this.qrcodelist.qrcode_list){
						for( var i =0; i<this.qrcodelist.qrcode_list.length; i++ ){
							if(this.qrcodelist.qrcode_list[i].ploatform_id * 1 == item.id * 1){
								flag = 1;
							}
						}
					}
					else{
						flag = 0;
					}
					
					return flag;
				}
			},
			datalength1() {
				return function(item) {
					var flag = 0;
					if(item){
						if(item.length!=0){
							return item.length;
						}
						else{
							return 0;
						}
					}
					else{
						return 0;
					}
					
					// return flag;
				}
			},
		
		}
		}
	
</script>

<style lang="scss" scoped src="./index.scss"></style>
